From 7353b8245193365720cd09147e6dbf15e60380ab Mon Sep 17 00:00:00 2001 From: "kfraser@localhost.localdomain" Date: Mon, 26 Feb 2007 16:25:17 +0000 Subject: [PATCH] x86: Clean up {alloc,free}_xen_pagetable() interface to avoid use of frame_table variable before initialisation. This wasn't a bug, but was confusing. Signed-off-by: Keir Fraser --- xen/arch/x86/mm.c | 6 +++--- xen/arch/x86/x86_32/mm.c | 15 ++++++++------- xen/arch/x86/x86_64/mm.c | 23 ++++++++++++++--------- xen/include/asm-x86/page.h | 4 ++-- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 8e7bdd44a9..1798be5e52 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -3401,7 +3401,7 @@ int map_pages_to_xen( { local_flush_tlb_pge(); if ( !(l2e_get_flags(ol2e) & _PAGE_PSE) ) - free_xen_pagetable(l2e_get_page(ol2e)); + free_xen_pagetable(page_to_virt(l2e_get_page(ol2e))); } virt += 1UL << L2_PAGETABLE_SHIFT; @@ -3413,14 +3413,14 @@ int map_pages_to_xen( /* Normal page mapping. */ if ( !(l2e_get_flags(*pl2e) & _PAGE_PRESENT) ) { - pl1e = page_to_virt(alloc_xen_pagetable()); + pl1e = alloc_xen_pagetable(); clear_page(pl1e); l2e_write(pl2e, l2e_from_page(virt_to_page(pl1e), __PAGE_HYPERVISOR)); } else if ( l2e_get_flags(*pl2e) & _PAGE_PSE ) { - pl1e = page_to_virt(alloc_xen_pagetable()); + pl1e = alloc_xen_pagetable(); for ( i = 0; i < L1_PAGETABLE_ENTRIES; i++ ) l1e_write(&pl1e[i], l1e_from_pfn(l2e_get_pfn(*pl2e) + i, diff --git a/xen/arch/x86/x86_32/mm.c b/xen/arch/x86/x86_32/mm.c index 76303fc275..291a503e4d 100644 --- a/xen/arch/x86/x86_32/mm.c +++ b/xen/arch/x86/x86_32/mm.c @@ -35,26 +35,27 @@ unsigned int PAGE_HYPERVISOR_NOCACHE = __PAGE_HYPERVISOR_NOCACHE; static unsigned long mpt_size; -struct page_info *alloc_xen_pagetable(void) +void *alloc_xen_pagetable(void) { extern int early_boot; extern unsigned long xenheap_phys_start; - struct page_info *pg; + unsigned long mfn; if ( !early_boot ) { void *v = alloc_xenheap_page(); - return ((v == NULL) ? NULL : virt_to_page(v)); + BUG_ON(v == NULL); + return v; } - pg = maddr_to_page(xenheap_phys_start); + mfn = xenheap_phys_start >> PAGE_SHIFT; xenheap_phys_start += PAGE_SIZE; - return pg; + return mfn_to_virt(mfn); } -void free_xen_pagetable(struct page_info *pg) +void free_xen_pagetable(void *v) { - free_xenheap_page(page_to_virt(pg)); + free_xenheap_page(v); } l2_pgentry_t *virt_to_xen_l2e(unsigned long v) diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c index 8ff4da2769..a2e38e7e22 100644 --- a/xen/arch/x86/x86_64/mm.c +++ b/xen/arch/x86/x86_64/mm.c @@ -36,22 +36,27 @@ unsigned int m2p_compat_vstart = __HYPERVISOR_COMPAT_VIRT_START; #endif -struct page_info *alloc_xen_pagetable(void) +void *alloc_xen_pagetable(void) { extern int early_boot; - unsigned long pfn; + unsigned long mfn; if ( !early_boot ) - return alloc_domheap_page(NULL); + { + struct page_info *pg = alloc_domheap_page(NULL); + BUG_ON(pg == NULL); + return page_to_virt(pg); + } /* Early pagetables must come from low 1GB of memory. */ - pfn = alloc_boot_low_pages(1, 1); /* 0x0 - 0x40000000 */ - return ((pfn == 0) ? NULL : mfn_to_page(pfn)); + mfn = alloc_boot_low_pages(1, 1); /* 0x0 - 0x40000000 */ + BUG_ON(mfn == 0); + return mfn_to_virt(mfn); } -void free_xen_pagetable(struct page_info *pg) +void free_xen_pagetable(void *v) { - free_domheap_page(pg); + free_domheap_page(virt_to_page(v)); } l2_pgentry_t *virt_to_xen_l2e(unsigned long v) @@ -63,7 +68,7 @@ l2_pgentry_t *virt_to_xen_l2e(unsigned long v) pl4e = &idle_pg_table[l4_table_offset(v)]; if ( !(l4e_get_flags(*pl4e) & _PAGE_PRESENT) ) { - pl3e = page_to_virt(alloc_xen_pagetable()); + pl3e = alloc_xen_pagetable(); clear_page(pl3e); l4e_write(pl4e, l4e_from_paddr(__pa(pl3e), __PAGE_HYPERVISOR)); } @@ -71,7 +76,7 @@ l2_pgentry_t *virt_to_xen_l2e(unsigned long v) pl3e = l4e_to_l3e(*pl4e) + l3_table_offset(v); if ( !(l3e_get_flags(*pl3e) & _PAGE_PRESENT) ) { - pl2e = page_to_virt(alloc_xen_pagetable()); + pl2e = alloc_xen_pagetable(); clear_page(pl2e); l3e_write(pl3e, l3e_from_paddr(__pa(pl2e), __PAGE_HYPERVISOR)); } diff --git a/xen/include/asm-x86/page.h b/xen/include/asm-x86/page.h index 31ec281920..1fa6d07cdc 100644 --- a/xen/include/asm-x86/page.h +++ b/xen/include/asm-x86/page.h @@ -363,8 +363,8 @@ static inline int get_order_from_pages(unsigned long nr_pages) } /* Allocator functions for Xen pagetables. */ -struct page_info *alloc_xen_pagetable(void); -void free_xen_pagetable(struct page_info *pg); +void *alloc_xen_pagetable(void); +void free_xen_pagetable(void *v); l2_pgentry_t *virt_to_xen_l2e(unsigned long v); /* Map machine page range in Xen virtual address space. */ -- 2.30.2